<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <?php
    $site_url = ".";
    $langs = require __DIR__ . '/mvc/Lang.php';
    $index = isset($_GET['index']) ? $_GET['index'] : 0;
    $lang = $langs[$index]['slug'];
    echo "<button id=\"execute\" type=\"button\">生成JSON</button> <span id=\"loading\"></span><br>";
    foreach ($langs as $i => $item) {
        echo "<a href=\"{$site_url}/{$item['slug']}/api/\" download=\"{$item['slug']}.json\" id=\"down-{$i}\">{$i} {$item['title']} ({$item['name']}) <span id=\"tip-{$i}\"></span></a><br>";
    }
    ?>
    <script>
        var count = '<?php echo count($langs); ?>';
        document.getElementById('execute').onclick = function(e) {
            var i = 0;
            document.getElementById('loading').innerText = 'Executing...'
            var timer = setInterval(function() {
                document.getElementById('down-' + i).click();
                document.getElementById('tip-' + i).innerText = 'done!';
                i++;
                if (i == count) {
                    document.getElementById('loading').innerText = 'All have done!'
                    clearInterval(timer);
                }
            }, 10000);
        };
    </script>
</body>

</html>